/**
 * defineStore - 定义仓库
 * 使用组合式api
 * export const use模块名Store = defineStore('模块名-唯一的id', () => {})
 * defineStore第二个参数是个回调函数
 * 要把你定义的东西全部return出去之后就能组件用了
 */
import { computed } from '@vue/reactivity';
import { defineStore } from 'pinia';
import { ref } from 'vue';
// modules
export const useCounterStore = defineStore('counter', () => {
    // state => ref 或者是 reactive
    const count = ref(0)
    // mutations => 定义方法
    const add = (num: number, str?: string) => {
        count.value += num
        console.log(str);
    }
    // actions => 定义方法
    const asyncAdd = (num: number) => {
        setTimeout(() => { 
            count.value += num
         }, 1000)
    }
    // getters => computed函数
    const doubleCount = computed(() => count.value * 2)
    return {
        count,
        add,
        asyncAdd,
        doubleCount
    }

})